#include <iostream>
#include <string>
using namespace std;

//模版的局限性
//模版并不是万能的，有些数据类型，需要用具体化方式做特殊实现

class Person
{
public:
    string name;
    int age;

    Person(string name, int age)
    {
        this->name = name;
        this->age = age;
    }
};

//对比两个数据是否相等的函数
template<class T>
bool compare(T& a, T& b)
{
    if (a == b)
        return true;
    else
        return false;
}

//利用具体化Person的版本实现代码，具体化优先调用
template<> bool compare(Person& p1, Person& p2)
{
    if (p1.name == p2.name && p1.age == p2.age)
    {
        return true;
    }
    return false;
}


void test1()
{
    int a = 10;
    int b = 99;

    bool ret = compare(a, b);
    if (ret)
    {
        cout << "a == b" << endl;
    }
    else
    {
        cout << "a != b" << endl;
    }
}

void test2()
{
    Person p1("Tom", 15);
    Person p2("Tom", 15);

    bool ret = compare(p1, p2);
    if (ret)
    {
        cout << "p1 == p2" << endl;
    }
    else
    {
        cout << "p1 != p2" << endl;
    }
}

int main()
{
    test2();
    return 0;
}